<?php
include("include/config.php");

/*
$path = "D:\WWW\seiscom.ro\data_seiscom";

$files1 = scandir($path);
foreach($files1 as $fisier){
	if ($fisier != "." && $fisier != ".."):
		#NIVEL 1
		$files2 = scandir($path . "\\" . $fisier);
		foreach($files2 as $fisier2){
			if ($fisier2 != "." && $fisier2 != ".."):
						#NIVEL 2
						$files3 = scandir($path . "\\" . $fisier . "\\" . $fisier2);
						foreach($files3 as $fisier3){
							if ($fisier3 != "." && $fisier3 != ".."):
									#NIVEL 3
									$files4 = scandir($path . "\\" . $fisier . "\\" . $fisier2 . "\\" . $fisier3);
									foreach($files4 as $fisier4){
										if ($fisier4 != "." && $fisier4 != ".."):
												#NIVEL 4
												$files5 = scandir($path . "\\" . $fisier . "\\" . $fisier2 . "\\" . $fisier3 . "\\" . $fisier4);
												foreach($files5 as $fisier5){
													if ($fisier5 != "." && $fisier5 != ".."):
														#NIVEL 5
															
															$an = $fisier;
															$tara = $fisier2;
															$statie = $fisier3;
															$senzor = $fisier4;
															$unda = $fisier5;
															
															#mysql_query("insert into unda (id_unda,an,tara,statie,senzor,unda,data_unda) values(null,'$an','$tara','$statie','$senzor','$unda',now())") or die(mysql_error());
															
															
															#echo  $path . "\\" . $fisier . "\\" . $fisier2 . "\\" . $fisier3 . "\\" . $fisier4 .  "\\" . $fisier5 . "<br/>";
													endif;
												}
										endif;
									}
									
							endif;
						}
					
			endif;
		}
		
	endif;
}
*/

/*

		$connection = ssh2_connect('91.212.254.15', 22);
		ssh2_auth_password($connection, 'lucian', 'Plucian');
		$sftp = ssh2_sftp($connection);
		
		


		$data = file_get_contents("ssh2.sftp://$sftp//home/rt/bulletins_ronet/auto/sent_by_email/2011326_18_47_35");
		$data = explode("Sta",$data);
$statii = explode("\n",$data[1]);
foreach($statii as $key => $val){
	echo substr($val,0,stripos($val," ")) . "<br/>";
}


*/

#$data = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address=42.3187,23.1893&sensor=false");
#$dataJs = json_decode($data);
#var_dump($dataJs);
#echo $dataJs->results[0]->address_components[4]->short_name
#echo $dataJs->{'results'}{'address_components'}{'short_name'};

/*
$fisier = "2014-04-20 11:43:51";
$fisier = str_replace("-","",$fisier);
$fisier = str_replace(":","_",$fisier);
$fisier = str_replace(" ","_",$fisier);
*/

$id_eveniment = 2;
$dataEveniment = "2014/04/18 18:05:53.89";
if(date("z",strtotime($dataEveniment) + 86400 ) < 100){
$fisier = date("Y0z_H_i_s", strtotime($dataEveniment) + 86400 );
}else{
$fisier = date("Yz_H_i_s", strtotime($dataEveniment) + 86400 );
}
$path = "buletine/";
$data = file_get_contents($path.$fisier);

/*
$connection = ssh2_connect('91.212.254.15', 22);
ssh2_auth_password($connection, 'lucian', 'Plucian');
$sftp = ssh2_sftp($connection);
$data = file_get_contents("ssh2.sftp://$sftp//home/rt/bulletins_ronet/auto/sent_by_email/2011326_18_47_35");
*/

$data = explode("Sta",$data);
$statii = explode("\n",$data[1]);

for($i=1;$i<count($statii);$i++){
		$statie = substr($statii[$i],0,stripos($statii[$i]," "));
		$res = mysql_query("select * from tari,statii where  cod_statie = '$statie' and statii.id_tara = tari.id_tara");
		while($row = mysql_fetch_array($res)){
			$cod_tara = $row['cod_tara'];
			$verficare_dublura_statie = mysql_query("select statie from evenimente_statii where statie = '$statie' and id_eveniment = '$id_eveniment' limit 1");
			if(mysql_num_rows($verficare_dublura_statie)==0){
				mysql_query("insert into evenimente_statii (id_statie_eveniment,id_eveniment,tara,statie) values(null,'$id_eveniment','$cod_tara','$statie')");
			}
			
		}
		
}

/*
foreach($statii as $key => $val){
	echo substr($val,0,stripos($val," ")) . "<br/>";
}
*/





/*
$connection = ssh2_connect('192.168.0.105', 22);
ssh2_auth_password($connection, 'root', 'newpaintcrew1');

$sftp = ssh2_sftp($connection);

$stream = fopen("ssh2.sftp://$sftp/errorfile.log", 'r');

echo $stream;
*/

















?>